<?php
class Act_outlets extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model( 'moutlets' );
		$this->load->library('enc');
	}
	
	public function getById( $id ) {
		if( isset( $id ) )
			echo json_encode( $this->mmaster->getOutlets( $id ) );
	}
	
	/*
	public function read( $kindOfRecord ) {
		echo json_encode( $this->moutlets->getOutlets( $kindOfRecord ) );
		//var_dump(json_encode( $this->moutlets->getOutlets( $kindOfRecord ) ));


	}
	*/
	
	
	public function read($kindOfRecord)
	{
		// $result = $this->moutlets->getOutlets($kindOfRecord);
		// echo json_encode($result);

		//20120719 ayu
		// encode
		$result = $this->moutlets->getOutlets($kindOfRecord);

        foreach ($result['aaData'] as $r => &$value) 
        {
            $value[0] = $this->enc->fogit($value[0]);
        }
        //penambahan nomor statis untuk grid SSP
        $start=$_GET['iDisplayStart'];
        $result['iDisplayStart']=$start;
		echo json_encode($result);
	}
	
	//fungsi untuk proses decode 
	function defoger()
    {
        $result = $this->enc->defog($this->input->post('str'));
        echo $result;  
    }

	public function delete( $table_type, $id = null ) {

		//decode id
    	$id = $this->enc->defog($id); 
    	
		if( is_null( $id ) ) {
			echo 'ERROR: Id not provided.';
			return;
		}
		$this->moutlets->deleteOutlet( $table_type, $id );
		
		$this->session->set_flashdata('message', 'Data Outlet berhasil dihapus');
		redirect(base_url()."index.php/master/outlets");
		
		echo 'Records deleted successfully';
	}
}